home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: Recursive Definition?
- Date: 18 Jan 1996 01:03:02 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4dk686$9d8@colossus.holonet.net>
- References: <4df39j$f80@news.vcd.hp.com> <4dish8$43c@is.bbsrc.ac.uk>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Robert Tuck (Robert.Tuck@bbsrc.ac.uk) wrote:
- : [...]
- : > static const Switch On;
- : > static const Switch Off;
- : [...]
- : >const Switch Switch::On = 1;
- : >const Switch Switch::Off = 0;
- : >
- : >What are the above two statements trying to initialize?
- : >It seems to me that they are sort of doing a recursive
- : >initialization. Please help!!!!
-
- : It looks to me like On and Off should be ints, not Switchs. The
- : respective lines should read:
-
- : static const int On;
- : static const int Off;
-
- : and
-
- : const int Switch::On = 1;
- : const int Switch::Off = 0;
-
- : A member of a class cannot be an object of that same class.
-
- Yes it can, if it's a *static* member. Infinite recursion does not
- occur, since there's only one copy of each static per program.
- The static members are not physically inside Switch objects, but
- rather, merely inside the Switch:: scope. I admit it looks a bit
- confusing at first.
-
- It might be very useful to have Switch::On/Off be Switchs, e.g.
- a function like void foo(const Switch&) could be called with the
- ready-made constant Switch::On, without having to construct a
- Switch on the fly.
- --
- Russell Blackadar, russell@mdli.com
-